import subprocess
from PySide6.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QTextEdit,QPlainTextEdit,QScrollBar
from PySide6.QtCore import Signal, Slot,Qt
 
class BatRunner(QWidget):
    max_lines = 5
    def __init__(self):
        super().__init__()
        self.init_ui()
 
    def init_ui(self):
        self.text_box = QPlainTextEdit(self)
        self.text_box.setReadOnly(True)
        self.text_box.setUndoRedoEnabled(False)
        self.text_box.setMaximumBlockCount(18)
        self.scrolbar=QScrollBar(self)
        self.text_box.setVerticalScrollBar(self.scrolbar)
        self.text_box.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn)

        self.run_button = QPushButton('Run Batch', self)
        self.run_button.clicked.connect(self.run_batch)
 
        layout = QVBoxLayout()
        layout.addWidget(self.text_box)
        layout.addWidget(self.run_button)
        
        
        self.setLayout(layout)
        self.setWindowTitle('Bat Runner')
        self.show()
    
    def run_batch(self):
        # 假设批处理文件路径是 'path_to_batch_file.bat'
        bat_file = 'install.bat'
        process = subprocess.Popen(bat_file, stdout=subprocess.PIPE, text=True)
        self.text_box.appendPlainText(process.stdout.read())
 
def main():
    app = QApplication([])
    window = BatRunner()
    app.exec()
 
if __name__ == '__main__':
    main()